package tec;

abstract class PassagerAbstrait implements Usager , Passager {
    private String nom;
    private int destination;
    private static final EtatPassager EtatAssis = new EtatPassager(Etat.ASSIS);
    private static final EtatPassager EtatDebout = new EtatPassager(Etat.DEBOUT);
    private static final EtatPassager EtatDehors = new EtatPassager(Etat.DEHORS);
    private EtatPassager monEtat;
    private CaracterePassager caractere;

    PassagerAbstrait(String nom, int destination, CaracterePassager c) {
	this.nom = nom;
	this.destination = destination;
	monEtat = EtatDehors;
	this.caractere = c;
    }
    
    public String nom() {
	return nom;
    }
    
    final protected EtatPassager monEtat() {
	return monEtat;
    }

    final protected int destination()
    {
	return destination;
    }

    public final boolean estDehors() {
	return monEtat.estExterieur();
    }
    
    public final boolean estAssis() {
	return monEtat.estAssis();
    }
    
    public final boolean estDebout() {
	return monEtat.estDebout();
    }
    
    public final void accepterSortie() {
	monEtat = EtatDehors;
    }
    
    public final void accepterPlaceAssise() {
	monEtat = EtatAssis;
    }
    
    public final void accepterPlaceDebout() {
	monEtat = EtatDebout;
    }
    
    public void monterDans(Transport t) throws TecInvalidException{
	
	if(!(t instanceof Bus)){
		throw new TecInvalidException();
	}
	Bus b = (Bus) t;
	choixPlaceMontee(b);
    }
    
    public void nouvelArret(Bus bus, int numeroArret) {
	if(estAssis() || estDebout()){
	    if(numeroArret == destination())
		bus.demanderSortie(this);
	    else
		this.caractere.choixChangerPlace(bus, numeroArret, this);
	}else{
	    throw new java.lang.IllegalStateException();
	}
    }

    abstract void choixPlaceMontee(Bus b);
    
    @Override
	public String toString() {
	return nom() + " " + monEtat();
    }

}
